package b3.widget.basic
{
	import flash.display.Sprite;

	public class MaskProgressBar extends Sprite
	{
		//进度0 - 1
		private var _percentage:Number;
		//遮罩
		private var maskSprite:Sprite;
		
		public function MaskProgressBar(CProgressBar:Class, CProgressBarFrame:Class = null)
		{
			super();
			//外框
			if (CProgressBarFrame != null)
			{
				var progressBarFrameSprite:Sprite = new CProgressBarFrame();
				addChild(progressBarFrameSprite);
			}
			//进度条
			var progressBarSprite:Sprite = new CProgressBar();
			addChild(progressBarSprite);
			//遮罩
			maskSprite = new Sprite();
			maskSprite.graphics.beginFill(0x000000);
			maskSprite.graphics.drawRect(0, 0, progressBarSprite.width, progressBarSprite.height);
			maskSprite.graphics.endFill();
			addChild(maskSprite);
			progressBarSprite.mask = maskSprite;
			//初始化
			percentage = 0;
		}
		
		public function get percentage():Number
		{
			return _percentage; 
		}
		
		public function set percentage(percent:Number):void
		{
			this._percentage = Math.min(Math.max(percent, 0), 1);
			maskSprite.scaleX = _percentage;
		}
	}
}